const gisMap = this.getApiPage().getApiWidgetByAliasName('三维组件')
const detailForm = this.getApiPage().getApiWidgetByAliasName('judge-content').widgetObj._option
const dataSource = detailForm.dataSource
console.log('detailForm', detailForm)
gisMap.widgetObj.sullivan.initial()
// 最小化融合通讯窗口
gisMap.widgetObj.artemis.minimize();
gisMap.widgetObj.gisMap.setModalType('NONE')
// const playback = this.getApiPage().getApiWidgetByAliasName('playback')
// playback.hideWidget()

if (dataSource.sourceDeviceId) {
  const equipment = '/Basics/basics-main/system/equipmentObject/listDetailByEquipmentCode'
  // 打开实时视频
  const options = { method: 'GET', headers: { "Content-type": "application/json" } };
  fetch(`${equipment}?equipmentCode=${dataSource.sourceDeviceId}`, options)
    .then(res => res.json())
    .then(json => {
      console.log(json);
      if (json?.success && json.result) {
        const { rows } = json.result
        const data = rows[0]?.equipmentConfig?.gbVideoConfig
        var host = this.getApiPage().getVariables().find(x => x.name == "stream_url").value;
        gisMap.widgetObj.sullivan.close()
        if (data && data.sipUser && data.videoChannelId) {
          const playUrl = `${host}/api/v1/stream/rtc/play`
          gisMap.widgetObj.sullivan.initial()
          gisMap.widgetObj.sullivan.addPlayer(playUrl, `${data.sipUser}/${data.videoChannelId}`)
        } else {
          window.layer.msg('暂无设备号/通道号')
        }
      }
    })
}else {
  gisMap.widgetObj.sullivan.close();
  window.layer.msg('未关联摄像头');
}
